/*
 * Copyright (c) 2005 -2008 Reliable Source, Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Mozilla Public License v.1.1,
 * BSD, and Eclipse Public License v1.0 which accompanies this
 * distribution and is available at:
 *
 * 		http://www.eclipse.org/legal/epl-v10.html
 * 		http://www.opensource.org/licenses/bsd-license.php
 * 		http://www.mozilla.org/MPL/MPL-1.1.html
 *
 * Contributors:
 *     IBM Corporation	     -  http://ibm.com
 *     	- initial API and implementation
 *
 *     patientos.org         - http://patientos.org
 *     	- domain and database persistence layer
 *
 *     Reliable Source, Inc. - http://reliablesource.org
 *     	- Symbiosys Application Framework,
 *     	- Symbiosys Application, Symbiosys Product
 *
 */
package org.reliablesource.symbiosys.workbench.tests.adapters;

import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.Platform;

import org.eclipse.jface.resource.ImageDescriptor;

import org.eclipse.ui.model.WorkbenchAdapter;

import org.reliablesource.model.core.IReliableElement;
import org.reliablesource.model.core.IReliableNode;


/**
 *
 * MockWorkbenchAdapter.java<br>
 * Created on: Jun 27, 2008<br>
 *
 * @author <a href="mailto:dennis.park@gmail.com">Dennis Park</a>
 *
 * @category
 * @since 1.0
 */
public class MockWorkbenchAdapter extends WorkbenchAdapter implements IAdaptable {
    private IReliableElement adapted;

    /*
     * (non-Javadoc)
     * @see org.eclipse.ui.model.WorkbenchAdapter#getImageDescriptor(java.lang.Object)
     */
    @Override
    public ImageDescriptor getImageDescriptor(Object object) {
        return super.getImageDescriptor(object);
    }

    /*
     * (non-Javadoc)
     * @see org.eclipse.ui.model.WorkbenchAdapter#getLabel(java.lang.Object)
     */
    @Override
    public String getLabel(Object object) {
        if (object instanceof IReliableElement) {
            return ((IReliableElement) object).getName();
        }

        return super.getLabel(object);
    }

    /*
     * (non-Javadoc)
     * @see org.eclipse.ui.model.WorkbenchAdapter#getParent(java.lang.Object)
     */
    @Override
    public Object getParent(Object object) {
        if (object instanceof IReliableElement) {
            return ((IReliableElement) object).getParent();
        }

        return super.getParent(object);
    }

    /*
     * (non-Javadoc)
     * @see org.eclipse.ui.model.WorkbenchAdapter#getChildren(java.lang.Object)
     */
    public Object[] getChildren(Object object) {
        if (object instanceof IReliableNode) {
            return ((IReliableNode) object).getChildren();
        }

        return super.getChildren(object);
    }

    /*
     * (non-Javadoc)
     * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
     */
    public Object getAdapter(Class adapter) {
        return Platform.getAdapterManager().getAdapter(adapted, adapter);
    }

    /*
     *
     */
    public void setObjectToAdapt(IReliableElement _toAdapt) {
        Assert.isNotNull(_toAdapt);
        adapted = _toAdapt;
    }
}
